package cn.quan.evernote;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.drawable.BitmapDrawable;
import android.view.View;

/**
 * 
 * @author yunfeng.quan@gmail.com
 * 叠加到CameraView上，显示必要信息
 */
public class InfoView extends View {

	private final int MSG_COUNT_MAX = 10;
	private String[] message= new String[MSG_COUNT_MAX];
	private int picSizeWidth=0;
	private int picSizeHeight=0;
	private int uploadCount=0;
    private Bitmap btnCamera = null;

	public InfoView(Context context) {
		super(context);
		setFocusable(true);
		for(int i=0 ;i<MSG_COUNT_MAX;i++){
			message[i] = "";
		}
        btnCamera = ((BitmapDrawable)getResources().getDrawable(R.drawable.camera2)).getBitmap();

	}

	@Override
	protected void onDraw(Canvas canvas) {
		// TODO Auto-generated method stub
		super.onDraw(canvas);
		canvas.drawColor(Color.TRANSPARENT);//透明背景
           
         //文字颜色属性
         Paint textPaint = new Paint();  
         textPaint.setStyle(Paint.Style.FILL);  
         textPaint.setARGB(255, 255, 0, 0);  
           
         //输出文字
         for(int i=0;i<MSG_COUNT_MAX;i++){
        	 if(message[(MSG_COUNT_MAX - 1)- i] != null){
        		 canvas.drawText(message[(MSG_COUNT_MAX - 1)- i], 20, 20*(i+3), textPaint);  
        	 }
         }
         if(picSizeWidth>0 && picSizeHeight>0){
        	 canvas.drawText("size:"+picSizeWidth+"x"+picSizeHeight, 20, 20, textPaint);  
         }
         if(uploadCount>0){
        	 canvas.drawText("count:"+uploadCount, 20, 40, textPaint);  
         }
         //Shutter区域
         Paint shutterPaint = new Paint();
         shutterPaint.setStyle(Paint.Style.STROKE);
         shutterPaint.setARGB(255, 102, 0, 255);
         RectF shutterRect = new RectF();
         shutterRect.left = (float)(this.getWidth()*0.70);
         shutterRect.top = (float)(this.getHeight()*0.05);
         shutterRect.right = (float)(this.getWidth()*0.98);
         shutterRect.bottom = (float)(this.getHeight()*0.4);
         canvas.drawRoundRect(shutterRect, 10f,10f,shutterPaint);
         canvas.drawBitmap(btnCamera, shutterRect.left,shutterRect.top, shutterPaint);
         
	}
	
	public void notifyMessage(String msg){
		if(msg != null){
			if(msg.length()>0){
				for(int i = (MSG_COUNT_MAX - 1);i>0;i--){
					message[i] = message[i - 1];
				}
				message[0] = msg;
				invalidate();
			}
		}
	}
	public void notifyPicSize(int width,int height){
		picSizeWidth = width;
		picSizeHeight = height;
		invalidate();
	}
	public void notifyInc(){
		uploadCount ++;
	}
	public void notifyDec(){
		uploadCount --;
	}
}
